<template>
	<div >
		<el-dialog v-model="isShowDialog" :title="props.title" :width="700" draggable="">
			<el-form :model="ruleForm" ref="ruleFormRef" size="default" label-width="100px" :rules="rules">
				<el-row >
				
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
			              <el-form-item label="控制叉">
							<el-select v-model="ruleForm.usePoke"  >
						    <el-option
						      v-for="item in pokes"
						      :key="item.value"
						      :label="item.label"
						      :value="item.value"
						    />
						  </el-select>
			              </el-form-item>
			              </el-col>
        

                     
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="堆垛机编号" prop="num">
							<el-input v-model="ruleForm.num" placeholder="堆垛机编号" clearable />
							
						</el-form-item>
						
					</el-col>
                   
        <el-row v-if="ruleForm.pokeUse==1 || ruleForm.pokeUse>2">      
         <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">      
           <el-form-item label="列" prop="toBank">
							<el-input v-model="ruleForm.fromX" placeholder="取货列" clearable />							
						</el-form-item>						
				 </el-col>
         <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
						<el-form-item label="行" prop="toBay">
							<el-input v-model="ruleForm.fromY" placeholder="取货行" clearable />							
						</el-form-item>						
					</el-col>
         <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
						<el-form-item label="段" prop="toLevel">
							<el-input v-model="ruleForm.fromZ" placeholder="取货段" clearable />							
						</el-form-item>						
				 </el-col>
         <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
						<el-form-item label="列" prop="toBank">
							<el-input v-model="ruleForm.toX" placeholder="去向列" clearable />							
						</el-form-item>						
				 </el-col>
         <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
						<el-form-item label="行" prop="toBay">
							<el-input v-model="ruleForm.toY" placeholder="去向行" clearable />							
						</el-form-item>						
					</el-col>
         <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
						<el-form-item label="段" prop="toLevel">
							<el-input v-model="ruleForm.toZ" placeholder="去向段" clearable />							
						</el-form-item>						
					</el-col>

         <el-col  :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="托盘" prop="toLevel">
							<el-input v-model="ruleForm.tray" placeholder="托盘" clearable />							
						</el-form-item>						
				 </el-col>
         <el-col  :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="托盘2" prop="toLevel">
							<el-input v-model="ruleForm.tray2" placeholder="托盘2" clearable />							
						</el-form-item>						
				 </el-col>
        </el-row>
       

        <el-row v-if="ruleForm.pokeUse==2 || ruleForm.pokeUse==3">    
          <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
						<el-form-item label="列" prop="toBank">
							<el-input v-model="ruleForm.fromX2" placeholder="取货列" clearable />							
						</el-form-item>						
					</el-col>
         <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
						<el-form-item label="行" prop="toBay">
							<el-input v-model="ruleForm.fromY2" placeholder="取货行" clearable />							
						</el-form-item>						
					</el-col>
                    <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
						<el-form-item label="段" prop="toLevel">
							<el-input v-model="ruleForm.fromZ2" placeholder="取货段" clearable />							
						</el-form-item>						
					</el-col>

          <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
						<el-form-item label="列" prop="toBank">
							<el-input v-model="ruleForm.toX2" placeholder="去向列" clearable />							
						</el-form-item>						
					</el-col>
                    <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
						<el-form-item label="行" prop="toBay">
							<el-input v-model="ruleForm.toY2" placeholder="去向行" clearable />							
						</el-form-item>						
					</el-col>
                    <el-col  :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
						<el-form-item label="段" prop="toLevel">
							<el-input v-model="ruleForm.toZ2" placeholder="去向段" clearable />							
						</el-form-item>						
					</el-col>

          <el-col  :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="托盘" prop="toLevel">
							<el-input v-model="ruleForm.rightTray" placeholder="托盘" clearable />							
						</el-form-item>						
					</el-col>
          <el-col  :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="托盘2" prop="toLevel">
							<el-input v-model="ruleForm.rightTray2" placeholder="托盘2" clearable />							
						</el-form-item>						
					</el-col>

        </el-row>
         


        

					
					
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<!--<el-button @click="cancel" size="default">取 消</el-button>-->
                    <el-button @click="reset" size="default">复 位</el-button>
                    <!---<el-button @click="run" size="default">启 动</el-button>
                    <el-button @click="stop" size="default">停 止</el-button>
                    <el-button @click="deleteTask" size="default">删除任务</el-button>-->
					<el-button type="primary" @click="submit" size="default">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script lang="ts" setup>
	import { ref,onMounted } from "vue";
	import { ElMessage,ElMessageBox } from "element-plus";
	import type { FormRules } from "element-plus";
	import { WriteSc29 } from '/@/api/main/grpcServer';
	//父级传递来的参数
	var props = defineProps({
	title: {
	type: String,
	default: "",
	},
	});
	//父级传递来的函数，用于回调
	const emit = defineEmits(["reloadTable"]);
	const ruleFormRef = ref();
	const isShowDialog = ref(false);
	const ruleForm = ref<any>({});
		//自行删除非必填规则
		const rules = ref<FormRules>({
  
  
  pokeUse: [{required: true, message: '选择叉！', trigger: 'blur'}],
  
  num: [{required: true, message: '编号！', trigger: 'blur'}]
  
});
const pokes=ref([]);
const options = [
  {
    value: 1,
    label: '左叉',
  },
  {
    value: 2,
    label: '右叉',
  },
  {
    value: 3,
    label: '双叉',
  },
  {
    value: 4,
    label: '双放',
  } 
];




// 打开弹窗
const openDialog = (row: any) => {
  
  ruleForm.value = JSON.parse(JSON.stringify(row));
  if (row.unitNum=='1') {
    ruleForm.value.pokeUse=1;
    pokes.value=[{value:1,label:'单叉'}]
  }else{
    ruleForm.value.pokeUse=3;
    pokes.value=options;
  }
  isShowDialog.value = true;
};

// 关闭弹窗
const closeDialog = () => {
  emit("reloadTable");
  isShowDialog.value = false;
};

// 取消
const cancel = () => {
  isShowDialog.value = false;
};
// 复位
const reset = async() => {


  let data={
    
     reset:1,
	 num:ruleForm.value.num
    
  };
  ElMessageBox.confirm(
    '确认进行错误复位?',
    '警告',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(async() => {
		await WriteSc29(data);
  ElMessage({
        message: `操作成功`,
        type: "success",
      });
    })
    
 
 
};
// 启动
const run = async() => {
    let data={
   
  };
  await WriteSc(data);
  ElMessage({
        message: `操作成功`,
        type: "success",
      });
};
// 停止
const stop = async() => {
    let data={
    
  };
  await WriteSc(data);
  ElMessage({
        message: `操作成功`,
        type: "success",
      });
};
// 删除任务
const deleteTask = async() => {
    let data={
    
  };
  await WriteSc(data);
  ElMessage({
        message: `删除任务`,
        type: "success",
      });
};

// 提交
const submit = async () => {
  ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
    if (isValid) {
      let values = ruleForm.value;
      await WriteSc29(values);
      ElMessage({
        message: `提交成功`,
        type: "success",
      });
    } else {
      ElMessage({
        message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
        type: "error",
      });
    }
  });
};





// 页面加载时
onMounted(async () => {
});

//将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>




